﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Clonkd.ScheduledTask
{
    public class ScheduledTask
    {
        public ScheduledTask(string name) : this(name, new TimeSpan(24, 0, 0))
        {
        }

        public ScheduledTask(string name, TimeSpan executionInterval)
        {
            Name = name;
            TaskExecutionInterval = executionInterval;
            DateCreated = DateTime.Now;
        }

        public string Name
        {
            get;
            set;
        }

        public IExecution Work
        {
            get;
            set;
        }

        public TimeSpan TaskExecutionInterval
        {
            get;
            set;
        }

        public DateTime DateLastRun
        {
            get;
            set;
        }

        public DateTime DateCreated
        {
            get;
            set;
        }

        public bool IsRunning
        {
            get;
            internal set;
        }

        public bool ShouldRun()
        {
            return (DateTime.Now - DateLastRun) >= TaskExecutionInterval && !IsRunning;
        }
    }
}
